﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class NoteDAO : BaseService
    {
        /// <summary>
        /// 根据信息状态查询任务信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<Note> GetListPaging(int page, int pagesize,int state)
        {
            string hql = "from Note where 1=1";
            if (state == -99)
            {
                //hql += " and Issuer = " + userid;
            }
            else
            {
                hql +=  " and State =" + state;
            }
            hql += " order By AddDate Desc";
            return FindList<Note>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据信息状态查询任务信息条目数
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPaging(int state)
        {
            string hql = "select count(*) from Note where 1=1";
            if (state == -99)
            {
                //hql += " and Id = " + id;
            }
            else
            {
                hql +=  " and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }
        /// <summary>
        /// 查询出最新的一条会签参与人中包含登录用户Note信息
        /// </summary>
        /// <param name="worker"></param>
        /// <returns></returns>
        public Note GetNodeByWorker(int worker)
        {
           //保留意见
            //string hql = "from Note where Worker like '%," + worker + ",%' and State = 1 and Id not in(select NoteId from NoteResult where UserId= "+worker+") order by AddDate desc ";
            string hql = "from Note where Worker like '%," + worker + ",%' and State = 1  order by AddDate desc ";
            try
            {
                return DBHelper.ExecuteHQL(hql).List<Note>().First();
            }
            catch (Exception)
            {

                return null;
            }

        }

      
    }
}
